/**
 * @author: mattwang@tencent.com
 * @date: 2012-10-13
 */

#ifndef __VECTOR_UTIL_H__
#define __VECTOR_UTIL_H__

#include "type_def.h"

inline double dot_product(const DVector& a, const DVector& b) {
	double result = 0;
	for (size_t i = 0; i < a.size(); i++) {
		result += a[i] * b[i];
	}
	return result;
}

inline void add_mult(DVector& a, const DVector& b, double c) {
	for (size_t i = 0; i < a.size(); i++) {
		a[i] += b[i] * c;
	}
}

inline void add(DVector& a, const DVector& b) {
	for (size_t i = 0; i < a.size(); i++) {
		a[i] += b[i];
	}
}

inline void add_mult_into(DVector& a, const DVector& b, const DVector& c, double d) {
	for (size_t i = 0; i < a.size(); i++) {
		a[i] = b[i] + c[i] * d;
	}
}

inline void scale(DVector& a, double b) {
	for (size_t i = 0; i < a.size(); i++) {
		a[i] *= b;
	}
}

inline void scale_into(DVector& a, const DVector& b, double c) {
	for (size_t i = 0; i < a.size(); i++) {
		a[i] = b[i] * c;
	}
}

#endif // __VECTOR_UTIL_H__
